package com.coderman.infosys.auth.app.facadeimpl.user;

import com.coderman.infosys.auth.app.convert.UserGroupConvert;
import com.coderman.infosys.plat.auth.common.dto.PageDTO;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import com.coderman.infosys.plat.auth.common.page.PageBO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import com.coderman.infosys.auth.api.dto.user.UserGroupDTO;
import com.coderman.infosys.auth.api.facade.user.UserGroupQueryFacade;
import org.apache.dubbo.config.annotation.Service;
import com.coderman.infosys.auth.domain.bo.user.UserGroupBO;
import com.coderman.infosys.auth.domain.gataway.UserRoleQueryGataway;
import com.coderman.infosys.auth.domain.repository.UserRoleRepository;


/**
 * @Description:接口实现类
 * @Author：
 * @CreateTime：2022-01-02 15:27:39
 * @version v1.0
 */
@Service
public class UserGroupQueryFacadeImpl   implements UserGroupQueryFacade{

	private  Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserRoleRepository userRoleRepository;

    @Autowired
    private UserRoleQueryGataway userRoleQueryGataway;

    @Override
    public ResultDataDto<PageDTO> getPageList(PageDTO pageDTO){
        PageBO pageBO = pageDTO.convertToBO();
        List<UserGroupBO> userGroupBOList = userRoleQueryGataway.getUserGroupPageList(pageBO);
        List<UserGroupDTO> userGroupDTOList = UserGroupConvert.INSTANCE.userGroupBOs2dtoList(userGroupBOList);
        return ResultDataDto.success(pageDTO.initData(userGroupDTOList,pageBO.getTotalRows()));

    }

    @Override
    public ResultDataDto<UserGroupDTO> getByGroupCode(String groupCode){
        UserGroupBO userGroupBO = userRoleRepository.getByUserGroupCode(groupCode);
        return ResultDataDto.success(UserGroupConvert.INSTANCE.bo2dto(userGroupBO));
    }

    @Override
    public ResultDataDto<List<UserGroupDTO>> search(String search){
        List<UserGroupBO> userGroupBOList = userRoleQueryGataway.searchUserGroup(search);
        return ResultDataDto.success(UserGroupConvert.INSTANCE.userGroupBOs2dtoList(userGroupBOList));
    }

}